#!/bin/sh


get_and_load() {
    day=$1
    table_in_hbase=$2
    table_in_mysql=$3
    month=$4
    echo $day, $table_in_hbase, $table_in_mysql, $month

    logfile=cron_hbase_${table_in_hbase}.log

    JAVA_HOME=/opt/soft/java ./pull_data_from_hbase_to_local.py $day $table_in_hbase &>$logfile
    if [ $? -ne 0 ]; then
        cat $logfile | ~/pytools/smtpsend.py houpr@58.com "pull hbase $day $table_in_hbase error"
        exit 1
    fi

    ./createtable.py $month
    ./load_data_to_mysql.py $table_in_mysql data/${table_in_hbase}-${day}.txt $month &>>$logfile
}



cd `dirname $0`

if [ $# -eq 1 ]; then
    whichday="$1"
else
    whichday='-1 day'
fi

day=`date +%Y%m%d --date "$whichday"`
month=`date +%Y%m --date "$whichday"`
# dayofweek=`date +%u --date "$whichday"`
# weekofyear=`date +%W --date "$whichday"`

get_and_load $day 'ListAnalytics' 'list_analytics' $month &
#get_and_load $day 'DetailLogCount' 'detail_analytics' $month &
wait
